package NC84_完全二叉树结点数;


 class TreeNode {
     int val = 0;
     TreeNode left = null;
     TreeNode right = null;

     public TreeNode(int val) {
         this.val = val;

     }
 }
public class Solution {
    public int nodeNum(TreeNode head) {
        int leftH = 0;
        int rightH = 0;
        TreeNode left = head;
        TreeNode right = head;
        while (left != null){
            leftH++;
            left = left.left;
        }
        while (right != null){
            rightH++;
            right = right.right;
        }
        if (leftH == rightH){
            return (int)Math.pow(2, leftH) - 1;
        }
        return 1 + nodeNum(head.left) + nodeNum(head.right);
    }
}